package com.tianbao54.springboot.jpa.controller;

import com.tianbao54.springboot.jpa.model.Customer;
import com.tianbao54.springboot.jpa.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("customers")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @PostMapping(value = "add")
    public Customer addCustomer (@RequestBody Customer customer) {
        customerService.addCustomer(customer);
        long id = customer.getId();
        return customerService.findCustomerById(id);
    }
}
